package org.example.web.controller;

import org.example.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

//支付服务
@RestController
public class PayController {

    @Autowired
    private RestTemplate restTemplate;

    //浏览器来调用
    @GetMapping("/pay/user/{id}")

    @HystrixCommand(fallbackMethod = "payFallback")
    public User pay(@PathVariable("id") Long id){

        String url = "http://user-server/user/"+id;
        return restTemplate.getForObject(url,User.class);
    }
    //托底方法
    public User payFallback(@PathVariable("id") Long id){
        return new User(-1L,"此用户不存在","服务已失效");
    }
}
